import { homeBrand, homeBanner } from '@/api/home'

const state = {
  brandList: [],
  imgList: []
}

const mutations = {
  setBrandList (state, value) {
    state.brandList = value
  },
  setImgList (state, value) {
    state.imgList = value
  }
}

const actions = {
  async getBrandList ({ state, commit }) {
    if (state.brandList.length > 0) {
      return state.brandList
    }
    const { result } = await homeBrand()
    commit('setBrandList', result)
    return result
  },
  async getImgList ({ state, commit }) {
    if (state.imgList.length > 0) {
      return state.imgList
    }
    const { result } = await homeBanner()
    commit('setImgList', result)
    return result
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
